package com.wzl.customviewproject.fragment;

import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.wzl.customviewproject.R;
import com.wzl.customviewproject.adapter.ParentListAdapter;

import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;

/**
 * 作者：longxiansen
 * 功能：
 */
public class TestFragmentOne extends Fragment {
    static TestFragmentOne testFragmentOne;
    private RecyclerView rvChild;

    public static Fragment newInstance() {
/*        if (testFragmentOne == null) {
            testFragmentOne = new TestFragmentOne();
        }
        return testFragmentOne;*/
        return new TestFragmentOne();
    }

    @Nullable
    @org.jetbrains.annotations.Nullable
    @Override
    public View onCreateView(@NonNull @NotNull LayoutInflater inflater, @Nullable @org.jetbrains.annotations.Nullable ViewGroup container, @Nullable @org.jetbrains.annotations.Nullable Bundle savedInstanceState) {
        showLog("onCreateView");
        return LayoutInflater.from(getActivity()).inflate(R.layout.fragment_list,container,false);
    }

    @Override
    public void onViewCreated(@NonNull @NotNull View view, @Nullable @org.jetbrains.annotations.Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        showLog("onViewCreated");
        rvChild = view.findViewById(R.id.fragment_list);
        ArrayList<String> childList = new ArrayList<>();
        for (int i = 0; i < 15; i++) {
            childList.add("childView"+i);
        }
        rvChild.setLayoutManager(new LinearLayoutManager(getActivity()));
        ParentListAdapter parentListAdapter = new ParentListAdapter(getActivity(), childList);
        rvChild.setAdapter(parentListAdapter);
        rvChild.scrollToPosition(0);
    }

    private String TAG = "testOne";
    private void showLog(String str){
        Log.d(TAG, str+ "111: "+this.hashCode());
    }
    @Override
    public void onHiddenChanged(boolean hidden) {
        super.onHiddenChanged(hidden);
        showLog("onHiddenChanged");
    }

    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);
        showLog("setUserVisibleHint");
    }

    @Override
    public void onAttachFragment(@NonNull @NotNull Fragment childFragment) {
        super.onAttachFragment(childFragment);
        showLog("onAttachFragment");
    }

    @Override
    public void onAttach(@NonNull @NotNull Context context) {
        super.onAttach(context);
        showLog("onAttach");
    }

    @Override
    public void onCreate(@Nullable @org.jetbrains.annotations.Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        showLog("onCreate");
    }

    @Override
    public void onActivityCreated(@Nullable @org.jetbrains.annotations.Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        showLog("onActivityCreated");
    }

    @Override
    public void onStart() {
        super.onStart();
        showLog("onStart");
    }

    @Override
    public void onResume() {
        super.onResume();
        showLog("onResume");
    }

    @Override
    public void onPause() {
        super.onPause();
        showLog("onPause");
    }

    @Override
    public void onStop() {
        super.onStop();
        showLog("onStop");
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        showLog("onDestroyView");
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        showLog("onDestroy");
    }

    @Override
    public void onDetach() {
        super.onDetach();
        showLog("onDetach");
    }

}
